#include "models.hpp"

#include <assert.h>
#include <qlib/all.h>
#include "spdlog/spdlog.h"

namespace qbe::layer {

Model::Model() {}
Model::~Model() {}

void Model::add(qlib::Tag& tag) {
  auto& it = layers[tag];
  it.random();
  // it.load_layer(item);
};

void Model::add(UiMessage::LayerItemInfo& item) {
  auto& it = layers[qlib::Tag{item.layer_number, 0}];
  it.load(item);
};

void Model::edit(UiMessage::LayerItemInfo& item) {
  auto& it = layers[qlib::Tag{item.layer_number, 0}];
  //   auto& it = model.layers[qlib::Tag{item.edit_layer_number, 0}];
  it.load(item);
};

void Model::remove(UiMessage::LayerItemInfo& item) {
  auto it = layers.find(qlib::Tag{item.layer_number, 0});
  if (it != layers.end()) {
    layers.erase(it);
  }
}

void Model::remove(qlib::Tag& tag) {
  auto it = layers.find(tag);
  if (it != layers.end()) {
    layers.erase(it);
  }
}

}  // namespace qbe::layer